/* 
 * File:   main.cpp
 * Author: Administrator
 *
 * Created on 2016年9月23日, 下午9:21
 */

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include  "secd.h"

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    SecdVm vm;
    FILE *fp = fopen("C:\\Users\\Administrator\\Desktop\\cppsecd\\test.bin", "rb");
    fseek(fp, 0, SEEK_END); //移向END
    long filesize = ftell(fp);
    char *content = (char *) malloc(filesize);
    rewind(fp);
    fread(content, sizeof (char), filesize, fp);
    fclose(fp);
    cout << "filesize:" << filesize << endl;
    cout << "len:" << strlen(content) << endl;
    cout << "content:" << content << endl;
    cout << "content[0]:" << content[0] << endl;
    vm.load_binary(content, filesize);
    cout << "IP:" << vm.IP << endl;
    vm.run();
    Value *ret = vm.stack->top();
    vm.stack->pop();
    if (is_integer(ret)) {
        cout << "Result:" << int_value(ret) << endl;
    }
    return 0;
}

